<?php
defined( '_VALID_MOS' ) or die( 'Restricted access' );

/**
* @package Joomla
* @subpackage Users
*/
class HTML_uservip {
	/**
	 * VIP
	 * */
	//function showListCategories
	function showListCategories( &$title_page, &$total, &$rows ){
		global $mosConfig_live_site, $mosConfig_absolute_path;
		global $database, $my;
		
		require_once( $mosConfig_absolute_path .'/includes/HTML_toolbar.php' );
		$hiddenmain  = intval(mosGetParam($_REQUEST, 'hiddenmain', 0));
		
		if ($hiddenmain == 0 || !$hiddenmain){
		?>
		<script language="JavaScript" src="<?php echo $mosConfig_live_site;?>/includes/js/JSCookMenu_mini.js" type="text/javascript"></script>
		<script language="JavaScript" src="<?php echo $mosConfig_live_site;?>/includes/js/joomla.javascript.js" type="text/javascript"></script>
		<form name="adminForm" method="post" action=""<?php echo $styleForm;?>>
		<div class="user_heading">
			<div id="title_form"><?php echo $title_page;?></div>
			<div id="toolbar">
			<?php
			mosToolBar::startTable();
			mosToolBar::publishIcon();
			mosToolBar::unpublishIcon();
			mosToolBar::addNewIcon();
			mosToolBar::editIcon();
			mosToolBar::deleteIcon();
			mosToolBar::endtable();
			?>
			</div>
		</div>
		<table class="adminlist">
			<thead>
				<tr>
					<th width="5">
						<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo $total; ?>);" />
					</th>
					<th>Tên loại sản phẩm</th>
					<th>Nhóm sản phẩm</th>
					<th width="8%">Hiển thị</th>
					<th>Số sản phẩm</th>
				</tr>
			</thead>
			<tbody>
			<?php if ($total>0){
				for ($i=0; $i<count($rows); $i++){
				$link = sefRelToAbs("index.php?option=com_content&task=view&catid=".$rows[$i]->catid."&id=".$rows[$i]->id).$rows[$i]->name.".html";
				$linkEdit = sefRelToAbs("index.php?option=com_uservip&task=edit&id=".$rows[$i]->id."&hiddenmain=1").$rows[$i]->name.".html";
				$linkSec = sefRelToAbs("index.php?option=com_uservip&task=showcate&section=".$rows[$i]->section).$rows[$i]->name_sec.".html";
				if (($i+1)%2 == 0) $str_class = "row1"; else $str_class = "row0";
				if ($rows[$i]->published == 1){
					$img = 'tick.png';
					$alt = 'Hiển thị';
					$submit = 'unpublish';
				}else{
					$img = 'publish_x.png';
					$alt = 'Khóa';
					$submit = 'publish';
				}
				if ($rows[$i]->parent_id > 0) $str = '&nbsp;--&nbsp;'; else $str = '';
				?>
				<tr class="<?php echo $str_class;?>">
					<td><input type="checkbox" onclick="isChecked(this.checked);" value="<?php echo $rows[$i]->id;?>" name="cid[]" id="cb<?php echo $i;?>" /></td>
					<td><a href="<?php echo $linkEdit;?>"title="Cập nhật loại sản phẩm <?php echo $rows[$i]->title;?>"><?php echo $str;?><?php echo $rows[$i]->title;?></a></td>
					<td><a href="<?php echo $linkSec;?>"title="Lọc theo nhóm <?php echo $rows[$i]->title_sec;?>"><?php echo $rows[$i]->title_sec;?></a></td>
					<td align="center">
						<a onclick="return listItemTask('cb<?php echo $i;?>','<?php echo $submit;?>')" href="javascript: void(0);">
						<img src="<?php echo $mosConfig_live_site;?>/images/<?php echo $img;?>" width="12" height="12" border="0" alt="<?php echo $alt; ?>" />
						</a>
					</td>
					<td align="center">
					<?php
					$sql = "SELECT COUNT(*) FROM #__content WHERE catid=".$rows[$i]->id." AND user_id=".$my->id;
					$database->setQuery($sql);
					$total = $database->loadResult();
					echo $total; 
					?>
					sản phẩm
					</td>
				</tr>
				<?php }?>
			<?php }else{?>
				<tr>
					<td align="center" colspan="9"><b style="color:red;"><?php echo _CATE_NOT_FOUND;?></b></td>
				</tr>
			<?php }?>
			</tbody>
			<tfoot></tfoot>
		</table>
		<input type="hidden" name="option" value="com_user" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="hidemainmenu" value="0" />
		<input type="hidden" name="<?php echo josSpoofValue(); ?>" value="1" />
		</form>
		<?php
		}
	}
	
	//function editCategories
	function editCategories( &$row, &$lsSection, &$lsNewParentID ){
		global $mosConfig_live_site, $database, $mosConfig_absolute_path;
		require_once( $mosConfig_absolute_path .'/includes/HTML_toolbar.php' );
		
		$rowid = intval($row->id);

		mosCommonHTML::loadOverlib();
		mosCommonHTML::loadCalendar();
		mosMakeHtmlSafe( $row );
		?>
		<script language="JavaScript" src="<?php echo $mosConfig_live_site; ?>/includes/js/joomla.javascript.js" type="text/javascript"></script>
		<link rel="stylesheet" href="<?php echo $mosConfig_live_site; ?>/plugin/jwysiwyg/jwysiwyg/jquery.wysiwyg.css" type="text/css" />
		<script type="text/javascript" src="<?php echo $mosConfig_live_site; ?>/plugin/jwysiwyg/jwysiwyg/jquery.wysiwyg.js"></script>
		<script language="javascript" type="text/javascript">
		function submitbutton(pressbutton) {
			var form = document.adminForm;
			if (pressbutton == 'cancel') {
				submitform( pressbutton );
				return;
			}

			if (form.title.value ==""){
				alert("Vui lòng đặt tên loại sản phẩm !");
				form.title.focus();
			} else {
				submitform(pressbutton);
			}
		}
		</script>

		<form action="" method="post" name="adminForm" enctype="multipart/form-data">
		<div class="user_heading">
			<div id="title_form"><?php echo _UPDATE_PRODUCTCATE;?>: <small><?php echo $row->id ? 'Cập nhật' : 'Thêm mới';?></small></div>
			<div id="toolbar">
			<?php
			mosToolBar::startTable();
			mosToolBar::saveIcon();
			mosToolBar::cancelIcon();
			mosToolBar::endtable();
			?>
			</div>
		</div>
		<table class="adminlist">
		<tr>
			<th colspan="3">
			Chi tiết nhóm sản phẩm
			</th>
		<tr>
		<tr>
			<td>
			Tên loại sản phẩm:
			</td>
			<td colspan="2">
			<input class="inputbox" type="text" name="title" value="<?php echo stripslashes( $row->title ); ?>" size="50" maxlength="50" title="A short name to appear in menus" />
			</td>
		</tr>
		<tr>
			<td>
			Thuộc nhóm sản phẩm:
			</td>
			<td colspan="2">
			<select name="section" class="inputbox">
				<option value="">Chọn nhóm sản phẩm</option>
				<?php
				for ($i=0; $i<count($lsSection); $i++){
					if ($lsSection[$i]->id == $row->section) $selected = ' selected="selected"'; else $selected='';
					?>
					<option value="<?php echo $lsSection[$i]->id;?>"<?php echo $selected;?>><?php echo $lsSection[$i]->title;?></option>
					<?php
				}
				?>
			</select>
			<?php echo $lists['section']; ?>
			</td>
		</tr>
		<tr>
			<td>
			Thuộc loại sản phẩm:
			</td>
			<td colspan="2">
				<select name="parent_id" class="inputbox">
					<option value="0">Loại sản phẩm</option>
					<?php 
					for ($i=0; $i<count($lsNewParentID); $i++){
					if ($lsNewParentID[$i]->id == $row->parent_id)	echo $selected_1 = ' selected="selected"'; else $selected_1='';
					?>
					<option value="<?php echo $lsNewParentID[$i]->id;?>"<?php echo $selected_1;?> style="font-weight:bold;"><?php echo $lsNewParentID[$i]->title;?></option>
					<?php								
						$sql ="select id,title from #__categories where parent_id=".$lsNewParentID[$i]->id." order by ordering asc, id desc";
						$database->setQuery($sql);
						$lsParent1 = $database->loadObjectList();
						if (count($lsParent1)>0){
							for ($j=0; $j<count($lsParent1); $j++){
								if ($lsParent1[$j]->id == $row->parent_id)	echo $selected_2 = ' selected="selected"'; else $selected_2='';
								?>
								<option value="<?php echo $lsParent1[$j]->id;?>"<?php echo $selected_2;?>>-- <?php echo $lsParent1[$j]->title;?></option>
								<?php
								$sql ="select id,title from #__categories where parent_id=".$lsParent1[$j]->id." order by ordering asc, id desc";
								$database->setQuery($sql);
								$lsParent2 = $database->loadObjectList();
								if (count($lsParent2)>0){
									for ($k=0; $k<count($lsParent2); $k++){
										?>
										<option value="<?php echo $lsParent2[$k]->id;?>" disabled="disabled">&nbsp;&nbsp;&nbsp;-- <?php echo $lsParent2[$k]->title;?></option>
										<?php
									}
								}
							}
						}
					?>
					<?php }?>
				</select>
			</td>
		</tr>
		<?php
		$time = time();					
		if ($rowid==0){
			$ngay_nhap_sp = date('Y-m-d',$time);
		}else{
			$ngay_nhap_sp = $row->created;
		}
		?>				
		<tr>
			<td valign="top">
			Ngày cập nhật
			</td>
			<td>
			<input class="inputbox" type="text" name="created" id="created" size="25" maxlength="19" value="<?php echo $ngay_nhap_sp; ?>" />
			<input name="reset" type="reset" class="button" onclick="return showCalendar('created', 'y-mm-dd');" value="..." />
			</td>
		</tr>
		<tr>
			<td>
			Hiển thị:
			</td>
			<td>
			<input type="checkbox" name="published" value="1" <?php if($row->published==1) echo "checked='checked'"; ?> /> Hiển thị
			</td>
		</tr>
		<tr>
			<td valign="top" colspan="2">
			Mô tả về loại sản phẩm:
			</td>
		</tr>
		<tr>
			<td colspan="3">
			<textarea id="wysiwyg" rows="15" cols="90" name="description"><?php echo $row->description;?></textarea>
			</td>
		</tr>
		<tr>
			<td>
			Thứ tự:
			</td>
			<td>
			<input class="inputbox" type="text" name="ordering" value="<?php echo $row->ordering; ?>" size="10" />
			</td>
		</tr>
		</table>

		<input type="hidden" name="option" value="com_categories" />
		<input type="hidden" name="oldtitle" value="<?php echo $row->title ; ?>" />
		<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
		<input type="hidden" name="sectionid" value="<?php echo $row->section; ?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="redirect" value="<?php echo $redirect; ?>" />
		<input type="hidden" name="hidemainmenu" value="0" />
		<input type="hidden" name="<?php echo josSpoofValue(); ?>" value="1" />
		</form>
		<script language="javascript" type="text/javascript">
		$(document).ready(function () {
			$('.inputbox').css('width','250px');
			$(function(){
				$('#wysiwyg').wysiwyg();
			})
		}); 
		</script>
		<?php
	}
	/**
	 * END VIP
	 * */
}

?>